<?php
/**
 * Created by lzl
 * Date: 2021 2021/9/8
 * Time: 9:18
 */
namespace App\Http\Controllers\Admin;


use App\Forms\BannerForms;

class BannerController extends Controller
{


    /**
     * 幻灯片列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
     * @throws \App\Exceptions\RequestException
     */
    public function bannerList()
    {
        if($this->request->ajax()) {
            $rules = [
                'page'       => 'required',
                'limit'      => 'required',
            ];

            $this->validateInput($rules);

            return $this->showJsonLayui((new BannerForms())->getBannerList($this->validated));
        }

        return $this->view('banner.banner_list');
    }


    /**
     * 新增|编辑 幻灯片
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
     * @throws \App\Exceptions\RequestException
     */
    public function editBanner()
    {

        $rules = [
            'url'      => 'nullable',
            'type'     => 'nullable',
            'id'       => 'nullable',
            'goods_id' => 'nullable',
        ];

        $this->validateInput($rules);

        $form = new BannerForms();

        if($this->request->isMethod('post')) {

            return $this->success($form->editBanner($this->validated));
        }

        return $this->view('banner.edit_banner', ['banner' => $form->getBannerOrNew($this->validated)]);
    }


    /**
     * 删除幻灯片
     * @return mixed
     * @throws \App\Exceptions\RequestException
     */
    public function deleteBanner()
    {
        $rules = [
            'id' => 'required|integer',
        ];

        $this->validateInput($rules);

        return $this->success((new BannerForms())->delete($this->validated));
    }
}